package com.speedricemanager.activity.home.fragmenadapter;

import android.content.Context;
import android.support.v7.widget.RecyclerView;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.Button;
import android.widget.LinearLayout;
import android.widget.TextView;

import com.jbm.jsm.iface.TaskMouldEntity;
import com.speedricemanager.R;

import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Date;


/**
 * Created by 李征 on 2017/12/17.
 */

public class RegisterauditAdapter extends RecyclerView.Adapter <RegisterauditAdapter.MyViewHoder>{
    private Context context;
    private ArrayList<TaskMouldEntity> arrayList;
    public RegisterauditAdapter(Context context, ArrayList<TaskMouldEntity> arrayList) {
        this.context = context;
        this.arrayList = arrayList;
    }
    @Override
    public MyViewHoder onCreateViewHolder(ViewGroup parent, int viewType) {
        return new MyViewHoder(LayoutInflater.from(context).inflate(R.layout.registeraydutlis_layout_item,parent,false));

    }

    @Override
    public void onBindViewHolder(MyViewHoder holder, final int position) {
        if (arrayList.get(position).getCreateDate()!=null){
            holder.shenqingshijian.setText(arrayList.get(position).getCreateDate()+"");}
        if (arrayList.get(position).getTmName()!=null){
            holder. mobanname.setText(arrayList.get(position).getTmName());}
        if (arrayList.get(position).getStartDate()!=null){
            holder. renwushijian.setText(" "+getTime(arrayList.get(position).getStartDate())+"   -    "+getTime(arrayList.get(position).getEndDate())+"");}
        if (arrayList.get(position).getRental()!=null){
            holder. zujin.setText(arrayList.get(position).getRental()+"");}
        if (arrayList.get(position).getStatuscn()!=null){
            holder. zhuangtai.setText(arrayList.get(position).getStatuscn()+"");}
        if (arrayList.get(position).getTmNo()!=null){
        holder. mobanbianhao.setText(arrayList.get(position).getTmNo());}
        if (arrayList.get(position).getCreateUser()!=null){
        holder.  teshenqingren.setText(arrayList.get(position).getCreateUser().getNickname());}

//        if (arrayList.get(position).getma()!=null){
//            holder.  teshenqingrenid.setText("("+arrayList.get(position).getCreateId()+")");
//        }

       if (arrayList.get(position).getPlatTypeS()!=null){
        holder. pingtai.setText(arrayList.get(position).getPlatTypeS());}
        switch (arrayList.get(position).getStatus()){
            case 2:
                holder.layoutcaozuoren.setVisibility(View.VISIBLE);
                break;
            case 3:
                holder.layoutcaozuoren.setVisibility(View.VISIBLE);
                holder.layoutjujueyuanyin.setVisibility(View.VISIBLE);
                break;
        }
        if (arrayList.get(position).getAuditCn()!=null){
            holder.caozuoren.setText(arrayList.get(position).getAuditCn());
        }
        if (arrayList.get(position).getRefuseReason()!=null){
            holder.jujieyuanyin.setText(arrayList.get(position).getRefuseReason());
        }
        holder.itemView.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                onClickListener.onClickListener(arrayList.get(position));
            }
        });
        if (arrayList.get(position).getStatus()==1){
            holder .jujueshenqing.setVisibility(View.VISIBLE);
        }

        if (arrayList.get(position).getCreateUser()
                != null) {
            String str = "";
            switch (arrayList.get(position).getCreateUser().getfId()){
                case 1:
                    str="紫马";
                    break;
                case 2:
                    str="橙马";
                    break;
                case 3:
                    str="黄马";
                    break;
                case 4:
                    str="红马";
                    break;
                case 5:
                    str="蓝马";
                    break;


        }
            holder.shenfen.setText(str);
        }


                holder .jujueshenqing.setOnClickListener(new View.OnClickListener() {
    @Override
    public void onClick(View view) {
        getonJujue.getJuJieShenQing(arrayList.get(position).getTmId());
    }
});



    }

    @Override
    public int getItemCount() {
        return arrayList.size();
    }

    class MyViewHoder extends RecyclerView.ViewHolder{
TextView shenqingshijian,mobanbianhao,mobanname,teshenqingren,renwushijian,pingtai,zujin,zhuangtai,caozuoren,jujieyuanyin,teshenqingrenid,shenfen;
        LinearLayout layoutcaozuoren,layoutjujueyuanyin;
        Button jujueshenqing;
        public MyViewHoder(View itemView) {
            super(itemView);
            shenqingshijian=itemView.findViewById(R.id.shenqingshijian);
            mobanbianhao=itemView.findViewById(R.id.mobanbianhao);
            mobanname=itemView.findViewById(R.id.mobanname);
            teshenqingren=itemView.findViewById(R.id.teshenqingren);
            renwushijian=itemView.findViewById(R.id.renwushijian);
            pingtai=itemView.findViewById(R.id.pingtai);
            zujin=itemView.findViewById(R.id.zujin);
            zhuangtai=itemView.findViewById(R.id.zhuangtai);
            caozuoren=itemView.findViewById(R.id.caozuoren);
            jujieyuanyin=itemView.findViewById(R.id.jujieyuanyin);
            layoutcaozuoren=itemView.findViewById(R.id.layoutcaozuoren);
            layoutjujueyuanyin=itemView.findViewById(R.id.layoutjujueyuanyin);
            teshenqingrenid=itemView.findViewById(R.id.teshenqingrenid);
            shenfen=itemView.findViewById(R.id.shenfen);
            jujueshenqing=itemView.findViewById(R.id.jujueshenqing);
        }
    }
public void getNotifinall(ArrayList<TaskMouldEntity> arrayLi){
    this.arrayList=arrayLi;
    notifyDataSetChanged();

}
    public String getTime(Date date){
        SimpleDateFormat format = new SimpleDateFormat("yyyyMMdd");
        return format.format(date);

    }
    onClickListener onClickListener;
    public void setOnClickListener(onClickListener onClickListener){
        this.onClickListener=onClickListener;



    }
  public   interface  onClickListener{
        void onClickListener(TaskMouldEntity taskMouldEntity);
    }

    GetonJujue getonJujue;
    public void getJujueshenqing(GetonJujue getonJujue){
        this.getonJujue=getonJujue;

    }

    public  interface GetonJujue{
        void getJuJieShenQing(int id);
    }
}
